<!DOCTYPE html>
<html>
<head>
	<title>修改商品信息</title>
	<include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>		
</head>
<body>

	<div class="layui-card">
		<button type="button" class="layui-btn" onclick="javascript:history.back(-1);"><i class="layui-icon layui-icon-return"></i> 返回</button>
		<div class="layui-card">
			<fieldset class="layui-elem-field layui-field-title layui-field-padding">
				<legend class="layui-legend-size">商品信息</legend>
				<form id="f">
					<input type="hidden" name="order_num" value="{$order_num}">
					<table  class="layui-table layui-nomargin" >
						<thead>
							<tr>
								<td>商品图片</td>
								<td>商品名称</td>
								<td>价格/货号</td>
								<td>属性</td>
								<td>数量</td>
								<td>库存</td>
								<td>小计</td>
							</tr>
						</thead>
						<tbody>
							<php>$count = 0;</php>
							<volist name="order_goods_list" id="vo">
								<tr>
									<input type="hidden" value="{$vo->id}" name="data[{$key}][id]">
									<td><img src="{$vo->order_goods_img}"></td>
									<td>{$vo->order_goods_name}</td>
									<td>
										<input type="text" class="layui-input" name="data[{$key}][order_goods_price]" value="{$vo->order_goods_price}" placeholder="请输入单价">
									</td>
									<td>{$vo->order_goods_spec}</td>
									<td>
										<input type="text" class="layui-input" name="data[{$key}][order_goods_num]" value="{$vo->order_goods_num}" placeholder="请输入数量">
									</td>
									<td>{$vo->order_goods_stock}</td>
									<td>
										<php>$count+= $vo->order_goods_price * $vo->order_goods_num;</php>
										{$vo->order_goods_price * $vo->order_goods_num}
									</td>
								</tr>
							</volist>
							<tr>
								<td colspan="7" align="right">
									合计：{$count}
								</td>
							</tr>
							<tr>
								<td colspan="7">
									<center>
										<button type="button" class="layui-btn layui-btn-normal submit-btn">提交</button>
									</center>
								</td>
							</tr>
						</tbody>
					</table>
				</form>
			</fieldset>
		</div>

<!-- 		<div class="layui-card">
			<form class="layui-form" id="add_goods">
				<fieldset class="layui-elem-field layui-field-title layui-field-padding">
					<legend class="layui-legend-size">添加商品</legend>
					<table  class="layui-table layui-nomargin" >
						<tr>
							<td width="10%">搜索商品</td>
							<td>
								<div>
									<div class="layui-input-inline">
										<select name="goods" lay-filter="list" lay-verify="required" lay-search="">
						          			<option value="0"></option>
						          			<volist name="list" id="vo">
						          				<option value="{$vo.id}">{$vo.goods_name}</option>
						          			</volist>>
						          		</select>
					          		</div>
				          		</div>
							</td>
						</tr>
						<tr>
							<td>商品名称</td>
							<td id="goods_name"></td>
						</tr>
						<tr>
							<td>递交店铺</td>						
							<td id="store_name"></td>
						</tr>
						<tr>
							<td>分类</td>
							<td id="cat"></td>
						</tr>
						<tr>
							<td>价格</td>
							<td id="shop_price"></td>
						</tr>
						<tr>
							<td>属性</td>
							<td id="spec"></td>
						</tr>
						<tr>
							<td>库存</td>
							<td id="inventory">
							</td>
						</tr>
						<tr>
							<td>数量</td>
							<td>
								<input type="text" class="layui-input" name="num" id="num" value="" placeholder="请输入数量">
							</td>
						</tr>
						<tr>
							<td>操作</td>
							<td>
								<button type="button" class="layui-btn layui-btn-normal " onclick="addGoods()">加入订单</button>
							</td>
						</tr>
					</table>
				</fieldset>
			</div> -->
		</form>

	</div>


	<include file='public/scripts'>
<script type="text/javascript">

	var form = layui.form;

	//提交检测
    $('.submit-btn').on('click',function(){
        $.ajax({
            url:"{:cmf_plugin_url('Order://admin_index/ordergoodsedit')}",
            type:'post',
            data:$('#f').serialize(),
			success:function(data){
				if (data.code == 1) {
					layer.msg(data.msg,{icon:1,time:1500},function(){
						window.location.replace("{:cmf_plugin_url('Order://admin_index/orderdetail')}?order_num={$order_num}");
					});
				} else {
					layer.msg(data.msg,{icon:2,time:1500});
				}
			},
			error:function()
			{
				layer.msg('系统错误',{icon:2,time:1500});
			}
        })   
    });

    var goods_id = '';
    //选择触发
	form.on('select(list)', function(data){
        let selectText=data.elem[data.elem.selectedIndex].value;//得到被选中的文本值
    	info = {};
    	info['id'] = selectText;
    	console.log(info);
        $.ajax({
            url:"{:cmf_plugin_url('Order://admin_index/getGood')}",
            type:'post',
            data:info,
			success:function(data){
				console.log(data);
				$('#goods_name').html(data.goods_name);
				$('#cat').html(data.cat);
				$('#spec').html(data.spec);
				$('#store_name').html(data.store_name);
				$('#shop_price').html(data.shop_price);
				$('#inventory').html(data.inventory);
				form.render();
			},
			error:function()
			{
				layer.msg('系统错误',{icon:2,time:1500});
			}
        })          

    }); 

    function addGoods()
    {
    	var data = $('#add_goods').serialize();
    	console.log(data);
    }   



</script>
</body>
</html>	